package com.contentteam.util.config.converter;

import java.io.File;

import org.apache.log4j.Logger;

public class FileConverter implements Converter<File>{

	private static final Log LOG = new Log();
	
	public File from(final String input) {
		final File file = new File(input);
		
		final boolean exists = file.exists();
		
		if( !exists ) {
			final String msg = LOG.fileNotExists(input);
			
			throw new RuntimeException( msg );
		}
		
		return file;
	}

	
	private static class Log {
		private static final Logger LOGGER = Logger.getLogger( FileConverter.class );

		public String fileNotExists(final String input) {
			final String logMsg = "File [= " + input + "] doesn't exists.";
			
			LOGGER.error( input );
			
			return logMsg;
		}
		
		
	}


	public String to(final File object) {
		return object.getAbsolutePath();
	}
	
}
